package com.wxproject.demo.Controller.Post;

import com.wxproject.demo.Common.lang.ResultBody;
import com.wxproject.demo.Entity.AO.PostAO;
import com.wxproject.demo.Mapper.PostMapper;
import com.wxproject.demo.Service.PostService;
import com.wxproject.demo.Utils.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author HCJ
 * @date 2021/4/24 16:36
 * @description
 *
 */
@RestController
@RequestMapping("post")
public class PostController {

    @Autowired
    PostService postService;

    @PostMapping("/createPost")
    public ResultBody createPost(@RequestBody @Validated PostAO postAO, HttpServletRequest rq) {
        String userId = JWTUtil.getUserId(rq.getHeader("Token"));
        return ResultBody.ok().data("create",postService.createPost(postAO,userId));
    }

    @PostMapping("/getPostByPage")
    public ResultBody getPostByPage(@RequestParam("page")int page,@RequestParam("size")int size){
        return ResultBody.ok().data("post",postService.getPostByPage(page,size));
    }
}
